﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Sharp.DataTransferObject.CMS;
using Sharp.Domain.CMSBoundedContext.AritcleModule.Aggregates;
using Sharp.Domain.CMSBoundedContext.AritcleModule.GatherEngine;
using Sharp.Domain.CMSBoundedContext.MemberModule.Aggregates;
using Sharp.Domain.CMSBoundedContext.OperationModule.Aggregates;
using Sharp.Domain.CMSBoundedContext.VIUModule.Aggregates;
using Sharp.Infrastructure.Interfaces;

namespace Sharp.Application.CMS
{
   public class Bootstraper: IBootstrapPlugin
    {
       public void Initialize()
       {
            Mapper.Initialize(cfg =>
            {


                #region VIU
                cfg.CreateMap<VIUDTO, VIU>()
                    .ReverseMap();
                cfg.CreateMap<ColumnDTO, Column>()
                    .ReverseMap();
                cfg.CreateMap<VIUCategoryDTO, VIUCategory>()
                    .ReverseMap();
                cfg.CreateMap<FieldDTO, Field>()
                    .ReverseMap();
                cfg.CreateMap<TagDTO, Tag>()
                     .ReverseMap();
                cfg.CreateMap<TagBDTO, Tag>()
                     .ReverseMap();
                cfg.CreateMap<MultiMediaDTO, MultiMedia>()
                     .ReverseMap();
                cfg.CreateMap<ApproveHistoryDTO, ApproveHistory>()
                     .ReverseMap();
                cfg.CreateMap<NoiseWordDTO, NoiseWord>()
                     .ReverseMap();
                cfg.CreateMap<IPBlackListDTO, IPBlackList>()
                     .ReverseMap();
                cfg.CreateMap<SpecialDTO, Special>()
                   .ReverseMap();
                cfg.CreateMap<ApproveHistory4SpecialDTO, ApproveHistory4Special>()
                    .ReverseMap();
                #endregion

                #region 会员相关
                cfg.CreateMap<CommentDTO, Comment>()
                                   .ReverseMap();
                cfg.CreateMap<FavoriteDTO, Favorite>()
                                  .ReverseMap();
                cfg.CreateMap<OAuthDTO, OAuth>()
                                  .ReverseMap();
                #endregion

                #region 基础库
                cfg.CreateMap<ArticleDTO, Article>()
                           .ReverseMap();
                #endregion

                //#region 主数据
                //var application = Assembly.LoadFrom(WebServer.MapPath(@"~\bin\QianShu.Domain.PlatformBoundedContext.dll"));
                //foreach (var type in application.GetTypes())
                //{
                //    if (type.GetInterface("IMasterData", false) == typeof(IMasterData))
                //    {
                //        cfg.CreateMap(type, typeof(MasterDataDTO))
                //        .ReverseMap();
                //    }
                //}
                //#endregion

                #region 采集
                cfg.CreateMap<GatherDTO, Gather>()
                    .ReverseMap();
                cfg.CreateMap<CategoryParameterDTO, CategoryParameter>()
                    .ReverseMap();
                cfg.CreateMap<WebParameterDTO, WebParameter>()
                    .ReverseMap();
                cfg.CreateMap<ClassGatherResultDTO, ClassGatherResult>()
                    .ReverseMap();
                cfg.CreateMap<ContentPageGatherResultDTO, ContentPageGatherResult>()
                    .ReverseMap();
                #endregion

            });
            this.IsAlready = true;
        }

       public bool IsAlready { get; set; }
    }
}
